package com.adong.test;

import com.adong.config.ProfileConfig;
import com.adong.pojo.Happiness;
import com.adong.pojo.User;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Profile;

/**
 * @author adong
 */

public class ProfileDemo {

    @Test
    public void demo(){
        //通过类型获得bean的名字
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ProfileConfig.class);
        String[] namesForType = applicationContext.getBeanNamesForType(Happiness.class);
        for (String name : namesForType) {
            System.out.println(name);
        }
    }

    @Test
    public void demo2(){
        //1.创造一个applicationContext
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        //2.设置需要激活的环境
        applicationContext.getEnvironment().setActiveProfiles("test","prod");
        //3.注册主配置类
        applicationContext.register(ProfileConfig.class);
        //4.启动刷新容器
        applicationContext.refresh();
        String[] namesForType = applicationContext.getBeanNamesForType(Happiness.class);
        for (String name : namesForType) {
            System.out.println(name);
        }
    }


}
